<?php
namespace plugin\router\src;

/**
 * Description of Router
 *
 * @author Fabrizio Filieri
 */
abstract class RouterConfig extends \bxd\core\plugin\PluginAbstract
{
	private $routerConfig;
	
	public function init()
	{
		// impostazione evento
		$this->setEvent(\bxd\core\event\Notify::$ON_BEFORE_PARSING_URL);
		
		// creazione del configuratore delle routes
		$this->routerConfig = new config\RouterConfig();
		
		// inizializzazione locale
		$this->onInit();
	}
	
	public function run()
	{
		// controllo della rotta
		RouterManager::getInstance()->setConfig($this->routerConfig)->match(\Bxd::getInstance()->requestUri);
	}
	
	public function addRoute($name, $route, $controller, $action, array $otherParam = array())
	{
		$this->routerConfig->route($name, $route, $controller, $action, $otherParam);
	}
	
	protected abstract function onInit();
}

?>
